{% macro form_group(field, helptext) -%}
<div class="form-group{% if field.errors %} has-error{% endif %}">
  {{ field.label(class_="control-label") }}
  {{ field(class_='form-control') }}
  {% if field.errors -%}
  {% for e in field.errors %}<p class="help-block text-danger">{{ e }}</p>{% endfor %}
  {%- elif helptext and not field.data -%}
  <p class="help-block">{{ helptext }}</p>
  {%- endif %}
</div>
{%- endmacro %}
{% macro render_pagination(pagination, endpoint) -%}
  <ul class="pagination">
    <!-- Prev link -->
    {% if pagination.has_prev -%}
      <li><a href="{{ url_for(endpoint, page=pagination.prev_num, **kwargs) }}">&laquo;</a></li>
    {%- else -%}
      <li class="disabled"><a href="#">&laquo;</a></li>
    {%- endif %}
    <!-- Page links -->
    {% for page in pagination.iter_pages() -%}
      {% if page -%}
        {% if page != pagination.page -%}
          <li><a href="{{ url_for(endpoint, page=page, **kwargs) }}">{{ page }}</a></li>
        {%- else -%}
          <li class="active"><a href="#">{{page}}<span class="sr-only">(current)</span></a></li>
        {%- endif %}
      {%- else -%}
        <li class="disabled"><a href="#">...</a></li>
      {%- endif %}
    {%- endfor %}
    <!-- Next link -->
    {% if pagination.has_next -%}
      <li><a href="{{ url_for(endpoint, page=pagination.next_num, **kwargs) }}">&raquo;</a></li>
    {%- else -%}
      <li class="disabled"><a href="#">&raquo;</a></li>
    {%- endif %}
  </ul>
{%- endmacro %}
